package com.tanhua.admin.controller;

import com.tanhua.admin.service.ManageService;
import com.tanhua.commons.utils.Constants;
import com.tanhua.model.vo.MovementVooo;
import com.tanhua.model.vo.MovementsVo;
import com.tanhua.model.vo.PageResult;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @author ck
 * @date 2021/11/19 13:12
 */

@RestController
@RequestMapping("/manage")
public class ManageController {


    @Autowired
    private ManageService manageService;

    /**
     * 分页查询用户信息
     *
     * @param page
     * @param pagesize
     * @return
     */
    @GetMapping("/users")
    public ResponseEntity users(@RequestParam(defaultValue = "1") Integer page,
                                @RequestParam(defaultValue = "10") Integer pagesize) {
        PageResult result = manageService.findAllUsers(page, pagesize);
        return ResponseEntity.ok(result);
    }

    /**
     * 查询用户详情
     */
    @GetMapping("/users/{userId}")
    public ResponseEntity findById(@PathVariable("userId") Long userId) {
        return manageService.findById(userId);
    }

    /**
     * 查询指定用户发布的所有视频列表
     */
    @GetMapping("/videos")
    public ResponseEntity videos(@RequestParam(defaultValue = "1") Integer page,
                                 @RequestParam(defaultValue = "10") Integer pagesize,
                                 Long uid) {
        PageResult result = manageService.findAllVideos(page, pagesize, uid);
        return ResponseEntity.ok(result);
    }

    /**
     * 查看动态列表
     */
    @GetMapping("/messages")
    public ResponseEntity messages(@RequestParam(defaultValue = "1") Integer page,
                                   @RequestParam(defaultValue = "10") Integer pagesize,
                                   Long uid, Integer state) {
        PageResult result = manageService.findAllMovements(page, pagesize, uid, state);
        return ResponseEntity.ok(result);
    }

    /**
     * 查看动态详情
     */
    @GetMapping("/messages/{id}")
    public ResponseEntity messagesContent(@PathVariable("id") String movementId) {
        MovementVooo vo = manageService.findMovementVo(movementId);
        return ResponseEntity.ok(vo);
    }

    /**
     * 评论列表翻页
     */

    @GetMapping("/messages/comments")
    public ResponseEntity comments(@RequestParam(defaultValue = "1", required = false) Integer page,
                                   @RequestParam(defaultValue = "10", required = false) Integer pagesize,
                                   @RequestParam String messageID) {
        ObjectId id = new ObjectId(messageID);
        PageResult pageResult = manageService.findMessageVo(page, pagesize, id);
        return ResponseEntity.ok(pageResult);
    }

    /**
     * 用户冻结
     */
    //用户冻结
    @PostMapping("/users/freeze")
    public ResponseEntity freeze(@RequestBody Map params) {
        Map map = manageService.userFreeze(params);
        return ResponseEntity.ok(map);
    }

    /**
     * 用户解冻
     */
    //用户解冻
    @PostMapping("/users/unfreeze")
    public ResponseEntity unfreeze(@RequestBody Map params) {
        Map map = manageService.userUnfreeze(params);
        return ResponseEntity.ok(map);
    }
}


